{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Python Crash Course.ipynb",
      "provenance": [],
      "authorship_tag": "ABX9TyOs5lI5J16gWJ6k2t4rcgLc"
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "0sJXME0OwKuk"
      },
      "source": [
        "# Python for Petroleum Engineers. "
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "YgdmKzaOyl-U"
      },
      "source": [
        "> ## Divyanshu Vyas\n",
        "Machine Learning Engineer (Oil & Gas) @ DICELYTICS | Founder, Petroleum From Scratch. \n",
        "\n",
        "> Motivations : Kendrick Lamar | J'Cole | Eminem"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "GsQ1gHHR0daB"
      },
      "source": [
        "## Why Python Though? \n",
        "\n",
        "1. Technical Edge and a smart one at that : Simulations | Automations | Quicker Problem Solving Mindset | Enhanced & Efficient Workflows.\n",
        "\n",
        "2. Oil & Gas Industry is very new to the Data Science and Machine Learning applications. \n",
        "\n",
        "3. Future of the Industry is hugely Data-Centric. \n",
        "\n",
        "4. Lot of Startups coming up that are solely based on DS/ML apps for bigger companies. They pay well. \n",
        "\n",
        "5. For someone who plans to diversify and smoothly transition to another industry/field - this is a very smart move. You can move into any domain. \n",
        "\n",
        "No. of Opportunities shoot up significantly!"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "6GjhG5YT1VIo"
      },
      "source": [
        "In this Course I'll cover the steps that helped me efficiently transition from Core PE to a Data Analytics PE. "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "XsKq8wqFwGiO"
      },
      "source": [
        "#######################################################################################################"
      ],
      "execution_count": 2,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "9LKlBCZk227t"
      },
      "source": [
        "#Python Crash Course \n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "4vaszy7LYIS-"
      },
      "source": [
        "# Chapter 1 : Data Types."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "nQsmrZO53CRU"
      },
      "source": [
        "## 1. Numbers & Mathematical Operators."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "2XCPgpPM210-",
        "outputId": "55eaaf55-b0cd-4eda-f288-28924373a2a1"
      },
      "source": [
        "1 + 1 "
      ],
      "execution_count": 5,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "2"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 5
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "CM0YuMF92LcI",
        "outputId": "5fb258e5-dff8-4dc9-a718-ca2b7e595e1c"
      },
      "source": [
        "1 - 1"
      ],
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 6
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "YdLOg-n23Qci",
        "outputId": "fa777df4-c1bd-4a99-c154-9ae22010d37b"
      },
      "source": [
        "1/2"
      ],
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0.5"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 7
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "iQgLWbq03RtH",
        "outputId": "c04bb7f8-f607-45b3-e1e7-b04b6ab7ee59"
      },
      "source": [
        "70.6*2.303"
      ],
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "162.59179999999998"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 8
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "JX65x01C3ZnY",
        "outputId": "00033c6a-20c5-476e-fa65-c1a3baf9f62e"
      },
      "source": [
        "round(70.6*2.303, 2)"
      ],
      "execution_count": 9,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "162.59"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 9
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "_cMD3UV53fS3",
        "outputId": "374310fb-6caa-4d37-e8fe-514e539a6169"
      },
      "source": [
        "# 5^2 = 25\n",
        "5**2"
      ],
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "25"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 10
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "v-5hfmt63ke6",
        "outputId": "b1363fb0-6711-41b2-bc61-fdd239f2e869"
      },
      "source": [
        "# Finding the Remainder after Division. \n",
        "5 % 2"
      ],
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "1"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 12
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "_hMYwurF3q8Q",
        "outputId": "5a315eee-2ee4-4543-dbef-0f037787a625"
      },
      "source": [
        "4 % 2"
      ],
      "execution_count": 14,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 14
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "rlyK4Li033K0",
        "outputId": "6881a9b4-0325-42d7-9235-235f45df46c9"
      },
      "source": [
        "## Floor Division : Returns the Quotient after division. \n",
        "5 // 2"
      ],
      "execution_count": 16,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "2"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 16
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "MoakU5jt41Ar"
      },
      "source": [
        "A // B -- Gives you the Quotient. \n",
        "\n",
        "A % B -- Gives you the Remainder. "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "HQoOxr6K33Im",
        "outputId": "62541a09-2291-4ee2-bc12-f84350421808"
      },
      "source": [
        "# Hence,\n",
        "\n",
        "# 5 = 2 * (5 // 2) + 5 % 2\n",
        "\n",
        "2 * (5 // 2) + 5 % 2"
      ],
      "execution_count": 17,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "5"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 17
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Rhq0NDFH5DYX"
      },
      "source": [
        ">### Subtopic : Variable Assignment"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "GaA0nAIy33F7"
      },
      "source": [
        "# Suppose reservoir A has porosity 25 % and Reservoir B has 30%. \n",
        "\n",
        "phi_A = 0.25 \n",
        "phi_B = 0.35"
      ],
      "execution_count": 18,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "GDV_Yalz33DG",
        "outputId": "99dc401d-369a-499a-a407-39fae5988fa2"
      },
      "source": [
        "phi_A , phi_B"
      ],
      "execution_count": 21,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(0.25, 0.35)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 21
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "vmNdD7Cy6SqU"
      },
      "source": [
        ">> #### Variable Name Rules. \n",
        "\n",
        "1. 1var : Invalid\n",
        "2. var1 : Valid\n",
        "\n",
        "3. Only special character allowed = Underscore _\n",
        "\n",
        "4. is Case Sensitive. A & a are different. "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 132
        },
        "id": "Np4GNtM233AN",
        "outputId": "f112b0ba-4cda-4020-f8ea-e897a41c1028"
      },
      "source": [
        "dx&dt = 5"
      ],
      "execution_count": 22,
      "outputs": [
        {
          "output_type": "error",
          "ename": "SyntaxError",
          "evalue": "ignored",
          "traceback": [
            "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-22-fee09c0b3e60>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m    dx&dt = 5\u001b[0m\n\u001b[0m             ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m can't assign to operator\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 132
        },
        "id": "IjBf9B616q_C",
        "outputId": "a663c780-ab40-4356-af4a-1e5398a7539e"
      },
      "source": [
        "# phi1 = 3\n",
        "\n",
        "1phi = 2"
      ],
      "execution_count": 27,
      "outputs": [
        {
          "output_type": "error",
          "ename": "SyntaxError",
          "evalue": "ignored",
          "traceback": [
            "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-27-8e8db5e216ea>\"\u001b[0;36m, line \u001b[0;32m3\u001b[0m\n\u001b[0;31m    1phi = 2\u001b[0m\n\u001b[0m       ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "fsWFD-TL309c"
      },
      "source": [
        "## 2. Strings"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "id": "ozV0gHUv3vpd",
        "outputId": "1d2593ca-bec9-4979-bf7a-1a553ffc0bf0"
      },
      "source": [
        "'single quotes are allowed'"
      ],
      "execution_count": 28,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            },
            "text/plain": [
              "'single quotes are allowed'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 28
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "id": "TCoJzNJt7CHG",
        "outputId": "15100eda-da8d-4191-a62b-89210ba113e4"
      },
      "source": [
        "\"Double Quotes are also allowed\""
      ],
      "execution_count": 29,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            },
            "text/plain": [
              "'Double Quotes are also allowed'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 29
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "GLC50bmU7jNB"
      },
      "source": [
        ">> #### Printing."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "WNN6pHeP7S-L",
        "outputId": "2a939e7e-c82a-47e6-efee-9670207e5a7f"
      },
      "source": [
        "print('This is Line1 \\nThis is Line2')"
      ],
      "execution_count": 35,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "This is Line1 \n",
            "This is Line2\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "hZ4ta1N47XSJ",
        "outputId": "40d8bb9d-deb8-4ef8-b3c1-aeccc135d009"
      },
      "source": [
        "name = 'Sandstone'\n",
        "porosity = 25 #percent. \n",
        "\n",
        "print('The rock type is name and the rock porosity is porosity')"
      ],
      "execution_count": 36,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "The rock type is name and the rock porosity is porosity\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "YfckAzYv8DgI"
      },
      "source": [
        "##### f-Strings."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "_oNywnYY720j",
        "outputId": "7aa17db2-a3be-408b-d437-4a5b71e50f98"
      },
      "source": [
        "print(f'The rock type is {name} and the rock porosity is {porosity} %')"
      ],
      "execution_count": 38,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "The rock type is Sandstone and the rock porosity is 25 %\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "VUWMIn2Z9VY2"
      },
      "source": [
        "Strings are Immutable/Cannot be modified."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 166
        },
        "id": "46TODMw89PoH",
        "outputId": "c542efe8-59b9-4a73-907d-b10b82cc943f"
      },
      "source": [
        "name[4] = 'r'"
      ],
      "execution_count": 41,
      "outputs": [
        {
          "output_type": "error",
          "ename": "TypeError",
          "evalue": "ignored",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-41-e815363d64e7>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mname\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'r'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
            "\u001b[0;31mTypeError\u001b[0m: 'str' object does not support item assignment"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "PKLi6ji19D35"
      },
      "source": [
        "## 3. Lists"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qv7DoNSgIafX"
      },
      "source": [
        "Number of objects stored in square brackets [ ]. \n",
        "\n",
        "Lists are Modify-able."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "guHq9kNm8X2J",
        "outputId": "1aabde45-4c0e-441e-97d1-25b8fc672c94"
      },
      "source": [
        "#list of integer type numbers. \n",
        "[1,2,3]"
      ],
      "execution_count": 43,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[1, 2, 3]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 43
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "rVjO_qveBc_0",
        "outputId": "344791bf-6a8b-40c9-ccae-30f8304ea0dc"
      },
      "source": [
        "#list of floating point numbers. \n",
        "[3.14 , 2.73, 0.87, 162.6]"
      ],
      "execution_count": 44,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[3.14, 2.73, 0.87, 162.6]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 44
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "M_o9LAUPBrTy",
        "outputId": "0236edcb-87b4-4ef2-f964-9cd5c6752dda"
      },
      "source": [
        "#mixed bag. \n",
        "['reservoir', 'drilling', 70.6, 141.2]"
      ],
      "execution_count": 45,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "['reservoir', 'drilling', 70.6, 141.2]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 45
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "aaCxBYw4Bz1G"
      },
      "source": [
        "#storing it into a variable. \n",
        "\n",
        "porosities = [0.2, 0.35, 0.4, 0.55]"
      ],
      "execution_count": 46,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "hwiaLInLB_zM"
      },
      "source": [
        "#### Operations and Manipulations on Lists. "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "uAp8VYcoB6UP",
        "outputId": "d1f0fc1d-8d72-4452-ff7b-ccab11e2d7aa"
      },
      "source": [
        "# Joining 2 Lists \n",
        "[1,2,3] + ['a','b','c']"
      ],
      "execution_count": 48,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[1, 2, 3, 'a', 'b', 'c']"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 48
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "gOMXCFtgB7aM"
      },
      "source": [
        "#APPEND\n",
        "new_value = 0.40\n",
        "porosities.append(new_value)"
      ],
      "execution_count": 50,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "EsrMY6BNCxd_",
        "outputId": "6f2b445d-c9af-4113-bedd-ffb0a2f5d021"
      },
      "source": [
        "porosities"
      ],
      "execution_count": 51,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[0.2, 0.35, 0.4, 0.55, 0.4]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 51
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "86BY4yYEC4wa"
      },
      "source": [
        "#Indexing. \n",
        "\n",
        "# Each Element in the list has an index starting with 0th index\n",
        "# for the first element. The same goes for strings as well. "
      ],
      "execution_count": 52,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "oIPEHavkDFCO",
        "outputId": "d73f9abb-9466-43f4-8225-5c38988514f8"
      },
      "source": [
        "porosities\n",
        "\n",
        "# porosities[0]"
      ],
      "execution_count": 56,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[0.2, 0.35, 0.4, 0.55, 0.4]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 56
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "IXCnbSqVDpVf",
        "outputId": "fb3a0fcd-c423-4cdb-9436-138826b75207"
      },
      "source": [
        "#Proof that lists are mutable/can be modified. \n",
        "poro = [0.20,0.22,0.34,0.27,45]\n",
        "\n",
        "#Notice that last porosity is mistakenly added as a percentage\n",
        "#We need it as a fraction. \n",
        "poro"
      ],
      "execution_count": 61,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[0.2, 0.22, 0.34, 0.27, 45]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 61
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "pHnpQjFrENmh"
      },
      "source": [
        "poro[-1] = 0.45"
      ],
      "execution_count": 62,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "WY2Wlm2wEjEQ",
        "outputId": "85626bf7-923a-4fad-c627-b07ba391e5b9"
      },
      "source": [
        "# 2D lists. \n",
        "\n",
        "list_1 = [1,2,3] \n",
        "list_2 = [4,5,6]\n",
        "\n",
        "list_2D = [list_1 , list_2]\n",
        "\n",
        "list_2D"
      ],
      "execution_count": 63,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[[1, 2, 3], [4, 5, 6]]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 63
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "U_iVeXD3FbmW",
        "outputId": "6c2faa8e-6405-4c89-eb16-cee4270c108b"
      },
      "source": [
        "list_2D[0][-1]"
      ],
      "execution_count": 65,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "3"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 65
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "bLGUZu7VF7uD"
      },
      "source": [
        "**List Slicing.**\n",
        "\n",
        "list_name[start:stop:step]"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "udaubIXKFfP4",
        "outputId": "a70910c3-6e34-423a-e7c9-74010de51592"
      },
      "source": [
        "#We can access a particular section or slice of a list.\n",
        "\n",
        "perms = [4,5,1,10,100,1000,3,40,50,60]\n",
        "\n",
        "perms[3:]"
      ],
      "execution_count": 68,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[10, 100, 1000, 3, 40, 50, 60]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 68
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "MbCmUgKdGG1o",
        "outputId": "e4ae81ab-f068-4484-c113-e8753113d2b5"
      },
      "source": [
        "perms[0:-1:2]"
      ],
      "execution_count": 69,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[4, 1, 100, 3, 50]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 69
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "yVlpiqexG3kx"
      },
      "source": [
        "## 4. Tuples"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "Hs6n2hawGV7z",
        "outputId": "a3f8f466-ab6f-4774-fdd4-e2d1949d1a5c"
      },
      "source": [
        "t = (1,2,3)\n",
        "\n",
        "t[0]"
      ],
      "execution_count": 70,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "1"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 70
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "c88BJGfeHJd1"
      },
      "source": [
        "#TUPLES are a SECURE way to store Data. \n",
        "\n",
        "#They help prevent modification. IMMUTABLE."
      ],
      "execution_count": 71,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 166
        },
        "id": "FXXpB3sRHQ6N",
        "outputId": "a9b41597-0329-4ddd-a6cf-5b793937058c"
      },
      "source": [
        "t[1] = 2"
      ],
      "execution_count": 72,
      "outputs": [
        {
          "output_type": "error",
          "ename": "TypeError",
          "evalue": "ignored",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-72-b9aa97991a78>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mt\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
            "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "IAOzK1ibHcuS"
      },
      "source": [
        "## 5. SETS"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "K8khvdy3HTtY"
      },
      "source": [
        "#MOST IMPORTANT application of Sets is that they help store \n",
        "#only unique information.\n",
        "\n",
        "set1 = {1,2,3}"
      ],
      "execution_count": 74,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "iPe7vNEJHZLk"
      },
      "source": [
        "duplicates = [1,2,2,3,4,5,6,6,6,6,7]"
      ],
      "execution_count": 76,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "o5YUKhshHbe1",
        "outputId": "c2c9e08f-7960-46c1-f153-f956fb8ee31b"
      },
      "source": [
        "set(duplicates)"
      ],
      "execution_count": 77,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "{1, 2, 3, 4, 5, 6, 7}"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 77
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "FbiACyKxIAgK"
      },
      "source": [
        "## 6. DICTIONARIES"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "la10z29ZH8si"
      },
      "source": [
        "reservoir1 = {'phi':[0.2,0.3,0.25],'K(mD)':[120,124,140]}"
      ],
      "execution_count": 79,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "htcZljeQH_yA",
        "outputId": "f274d92a-cea9-4fc9-e653-d6260f4b742c"
      },
      "source": [
        "reservoir1['phi']"
      ],
      "execution_count": 80,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[0.2, 0.3, 0.25]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 80
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "9nv3vqJwI7-B",
        "outputId": "9e646f7d-80a8-458f-8269-44910984afb6"
      },
      "source": [
        "reservoir1.keys()"
      ],
      "execution_count": 83,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "dict_keys(['phi', 'K(mD)'])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 83
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "Jzmku2G3I9aW",
        "outputId": "455ab534-ae2b-4e01-f04a-2368691bdedb"
      },
      "source": [
        "reservoir1.values()"
      ],
      "execution_count": 84,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "dict_values([[0.2, 0.3, 0.25], [120, 124, 140]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 84
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 138
        },
        "id": "CUfHG4BnJGKP",
        "outputId": "ba44c748-ea48-45b8-de2a-40739afe95a9"
      },
      "source": [
        "##Optional. Converting a dictionary to a table. \n",
        "import pandas as pd\n",
        "pd.DataFrame(reservoir1)"
      ],
      "execution_count": 85,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>phi</th>\n",
              "      <th>K(mD)</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0.20</td>\n",
              "      <td>120</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>0.30</td>\n",
              "      <td>124</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>0.25</td>\n",
              "      <td>140</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "    phi  K(mD)\n",
              "0  0.20    120\n",
              "1  0.30    124\n",
              "2  0.25    140"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 85
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ikyTEjC6Q2dG"
      },
      "source": [
        "# Chapter 2 : Operators & Statements."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "e54swgeMROwI"
      },
      "source": [
        "1. ### Comparison Operators"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "wz15P9gnJTng",
        "outputId": "ea71f9de-f5ba-474c-99e0-4c5288c9217e"
      },
      "source": [
        "1>2"
      ],
      "execution_count": 86,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "False"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 86
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "bMElx0MbQyxW",
        "outputId": "20ebb9d2-8e39-46ca-f30d-48b0d0b089d6"
      },
      "source": [
        "2>1"
      ],
      "execution_count": 87,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "True"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 87
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "mWkcwNXrRSxo",
        "outputId": "f96f1a02-0070-4dda-9fe4-36740e6c296e"
      },
      "source": [
        "1 == 1"
      ],
      "execution_count": 88,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "True"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 88
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "wLKFybgdRTzh",
        "outputId": "f693854b-b511-43ab-ad40-5fa91070d732"
      },
      "source": [
        "3 >= 1"
      ],
      "execution_count": 89,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "True"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 89
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "M8MtRIdCRVuE",
        "outputId": "b93b7239-6118-43ba-cf5a-9184bc9eaf3c"
      },
      "source": [
        "1 >= 3"
      ],
      "execution_count": 90,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "False"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 90
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "fHB0WUtORt2X"
      },
      "source": [
        "### 2. Logical Operators."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "nr3-Z1sTRXUY"
      },
      "source": [
        "# and | or | not | is"
      ],
      "execution_count": 91,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "VVph2TeVR0ex",
        "outputId": "cb06ce86-a361-4b71-89b8-2590ebd99727"
      },
      "source": [
        "(1 > 2) and (2 < 3)"
      ],
      "execution_count": 92,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "False"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 92
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "31YS3PxMR3bx",
        "outputId": "03059976-8892-4fe1-bc09-ee06d34bdf55"
      },
      "source": [
        "(1 > 2) or (2 < 3)"
      ],
      "execution_count": 93,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "True"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 93
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "SBiwAOotR5sY",
        "outputId": "02e4f8ed-5039-40a3-e5d1-1f7a11f8aa0f"
      },
      "source": [
        "(1 == 2) or (2 == 3) or (4 == 4)"
      ],
      "execution_count": 94,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "True"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 94
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "Ly2LiwaoR7go",
        "outputId": "76b7a22c-fe5c-4ec8-af0c-f3bb195691a6"
      },
      "source": [
        "not 1"
      ],
      "execution_count": 96,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "False"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 96
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "W4JyXHwJR83t",
        "outputId": "e1406ecb-8195-4399-e0f1-e24cd66b52e8"
      },
      "source": [
        "1 is 2"
      ],
      "execution_count": 98,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "False"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 98
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "VxLqMe8RStmi"
      },
      "source": [
        "3. ### if - elif - else Statements."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "U5fSdks1S1hp",
        "outputId": "0563e838-d5f6-4776-8939-c1fdde4ba47e"
      },
      "source": [
        "\n",
        "if 1 == 2:\n",
        "    print('first')\n",
        "elif 3 == 3:\n",
        "    print('middle')\n",
        "else:\n",
        "    print('Last')"
      ],
      "execution_count": 99,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "middle\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "Ru9jrpCsS8mb",
        "outputId": "f7005b40-d9b5-4dfd-fb61-db18bde11597"
      },
      "source": [
        "user_input = 'x'\n",
        "\n",
        "if type(user_input) == str:\n",
        "  print('Invalid Input')\n",
        "else:\n",
        "  if user_input % 2 == 0:\n",
        "    print('Even Number')\n",
        "  elif user_input % 2 != 0:\n",
        "    print('ODD Number')\n"
      ],
      "execution_count": 111,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Invalid Input\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "lbGHKtnGX6qf"
      },
      "source": [
        "# Chapter 3 : Loops / Iterations"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "KfkB4t6ZYNZa"
      },
      "source": [
        "### 1. for Loops."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "KLRPOhjCTSCp",
        "outputId": "98eba13e-1e93-4f4f-daa3-740804a8e6a9"
      },
      "source": [
        "liths = ['sst', 'dolo', 'lst', 'shale']\n",
        "\n",
        "for name in liths:\n",
        "  print(name)"
      ],
      "execution_count": 112,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "sst\n",
            "dolo\n",
            "lst\n",
            "shale\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "NcdcQVq5Tsa8",
        "outputId": "c8a5fa9e-5c9c-4695-b080-c921ed313399"
      },
      "source": [
        "nums = [1,2,3,4,5,6,7,8,9]\n",
        "\n",
        "for n in nums:\n",
        "  if n% 2 == 0:\n",
        "    print('EVEN')\n",
        "  else:\n",
        "    print('ODD')"
      ],
      "execution_count": 113,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "ODD\n",
            "EVEN\n",
            "ODD\n",
            "EVEN\n",
            "ODD\n",
            "EVEN\n",
            "ODD\n",
            "EVEN\n",
            "ODD\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "J2Lk7_1nY7gY"
      },
      "source": [
        "### 2. While Loops."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "2jGYd1FMYxeg",
        "outputId": "513eacef-ac23-452c-c5ae-09144298594a"
      },
      "source": [
        "#Keeps running as long as the condition is satisfied.\n",
        "i = 1\n",
        "while i < 5:\n",
        "    print('i is: {}'.format(i))\n",
        "    i = i+1"
      ],
      "execution_count": 115,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "i is: 1\n",
            "i is: 2\n",
            "i is: 3\n",
            "i is: 4\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "CzTNJiS2Y-3M",
        "outputId": "272b9084-163b-4b56-968b-88cf8b15e76a"
      },
      "source": [
        "#NOTE Range Function. \n",
        "range(10)"
      ],
      "execution_count": 116,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "range(0, 10)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 116
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "zhXbaoOhZy0F",
        "outputId": "98cee505-3796-4087-b67a-cee4977c97e7"
      },
      "source": [
        "for i in range(10):\n",
        "  print(i)"
      ],
      "execution_count": 117,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "0\n",
            "1\n",
            "2\n",
            "3\n",
            "4\n",
            "5\n",
            "6\n",
            "7\n",
            "8\n",
            "9\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "8EoLoKJxZ51Q"
      },
      "source": [
        "# Chapter 4 : Functions"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "g8cqFNniZ10e"
      },
      "source": [
        "def func_name():\n",
        "  #All you want to do in the function. \n",
        "  #return values if applicable. \n",
        "  pass"
      ],
      "execution_count": 118,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "J4LUmaR2aka0"
      },
      "source": [
        "#Example 1 : Take an input and return square. \n",
        "def squarer(x):\n",
        "\n",
        "  sq = x**2\n",
        "\n",
        "  return sq"
      ],
      "execution_count": 119,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "ChOycHO-ar2X",
        "outputId": "d495082a-4782-4a03-f824-395c11c6e905"
      },
      "source": [
        "squarer(2)"
      ],
      "execution_count": 120,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "4"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 120
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lAnAbpBNatkV"
      },
      "source": [
        "#Example 2 : Take in a number and power and raise number to\n",
        "# that power. \n",
        "\n",
        "def powerer(number, power):\n",
        "\n",
        "  result = number**power\n",
        "\n",
        "  return result"
      ],
      "execution_count": 121,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "FKIvbl8UbCxK",
        "outputId": "62eb293c-4c0a-42c4-f797-75f18cb1ecbc"
      },
      "source": [
        "powerer(625 , 0.5)"
      ],
      "execution_count": 122,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "25.0"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 122
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "pBK6WvfnjHaC"
      },
      "source": [
        "# Mini-Projects 1 : Hands on practice with Functions"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "UuH2oo31jLcF"
      },
      "source": [
        "#### Project 1 : Darcy's Law\n",
        "\n",
        "$ q = \\frac {kh} {141.2 \\mu B ln(re/rw) } \\triangle P $ "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "8I-jY6FYbGI6"
      },
      "source": [
        "#Functions are very important. \n",
        "\n",
        "#1. Make the code clean. \n",
        "#2. Helps Prevent repetitive commands."
      ],
      "execution_count": 123,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ZT27GCZYjzWh"
      },
      "source": [
        "#So here the term except delP is important. \n",
        "#And we can use it again and again. So we can create a function of it. \n",
        "\n",
        "#function definition. \n",
        "def slope():\n",
        "\n",
        "  k = int(input('Enter K: '))\n",
        "  h = int(input('Enter h: '))\n",
        "  mu = int(input('Enter viscocity: '))\n",
        "  B = float(input('Enter FVF: '))\n",
        "\n",
        "  lnrerw = 0.5\n",
        "\n",
        "  m = k*h/(141.2*mu*B*lnrerw)\n",
        "\n",
        "  return m"
      ],
      "execution_count": 124,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "LQRDbhB1j1Pt",
        "outputId": "77e4ecc4-1708-4b4f-d436-d77cec6fd903"
      },
      "source": [
        "#function call to get the value function returns. \n",
        "#Note that this example also teaches how to take user input.\n",
        "delP = 500 #psia\n",
        "\n",
        "m = slope()\n",
        "\n",
        "q = m*delP\n",
        "\n",
        "print(f'The flowrate at {delP} psi drawdown is {q} STB/D')"
      ],
      "execution_count": 125,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Enter K: 100\n",
            "Enter h: 30\n",
            "Enter viscocity: 70\n",
            "Enter FVF: 1.1\n",
            "The flowrate at 500 psi drawdown is 275.928037967698 STB/D\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "E7D0d8DQkGp8"
      },
      "source": [
        "#### Project 2 : Function to find API gravity."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "1uWwE3fDj4mi"
      },
      "source": [
        "def API(SG):\n",
        "\n",
        "  api = 141.5/SG - 131.5\n",
        "\n",
        "  return api"
      ],
      "execution_count": 126,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "F-u61-ZKkSRx",
        "outputId": "b07db1de-0717-45dc-e459-708455fccf50"
      },
      "source": [
        "API(1)"
      ],
      "execution_count": 127,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "10.0"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 127
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "4vlXVxNfkWVm"
      },
      "source": [
        "#### LAMBDA Functions / Anonymous Functions."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "RV7jj3jKkTb9",
        "outputId": "8fe5e78e-8863-4247-c409-3e72e0daa5a0"
      },
      "source": [
        "API = lambda SG : 141.5/SG - 131.5\n",
        "\n",
        "API(1)"
      ],
      "execution_count": 128,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "10.0"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 128
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "GZyP-tCQk0nZ"
      },
      "source": [
        "# Mini-Projects 2 : Hands on with Iterations."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "oiWSFkTnlkvO"
      },
      "source": [
        "## Solving for a root."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 269
        },
        "id": "cMKCVZ62kvJJ",
        "outputId": "6f9fa169-4a6c-4dba-896c-1809c5357520"
      },
      "source": [
        "#Can ignore on Day1. Can come back later and understand.\n",
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "\n",
        "x = np.linspace(-10,10)\n",
        "\n",
        "y1 = np.sin(x) ; y2 = x +1\n",
        "\n",
        "plt.plot(x,y1)\n",
        "plt.plot(x,y2)\n",
        "\n",
        "plt.axvline(root,color='red')\n",
        "\n",
        "plt.ylim(-3,3)\n",
        "plt.xlim(-5,5)\n",
        "\n",
        "plt.grid()"
      ],
      "execution_count": 151,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAD8CAYAAABq6S8VAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3dd3hU1drG4d9KD6RAKAFCIPQaJJBQRYKKgqBA6FWQpmJvx3Zsx3LUc7ChIArSewcLghKlSA2hQ2ihBJASEggESGbW98fgAf0QAjOZNeW9r4tLE8LeD5vJw2bP2u9WWmuEEEK4Lx/TAYQQQthHilwIIdycFLkQQrg5KXIhhHBzUuRCCOHmpMiFEMLN2V3kSqkgpdRapdQmpdQ2pdSbjggmhBCiYJS968iVUgooqrXOUUr5AyuAJ7XWqx0RUAghxPX52bsBbfubIOfyh/6Xf8hdRkII4SR2FzmAUsoX2ABUBT7XWq+5xtcMAYYABAcHN4yOjnbErm+Z1WrFx0feIihy6BBaa3IrVDAdxSXI6wKUthKcewRfy0XOFymHxTfYdCTjXOV1kZaWdlJrXeqvn7f70sqfNqZUMWAu8LjWeuvffV18fLxev369w/Z7K5KTk0lMTDSawSUkJpKVlUWx1FTTSVyC178u8i7A5C5wYBVb6rxEbJfnTSdyCa7yulBKbdBax//18w79K0ZrnQUsA9o4crtCCCew5MPsgZC+HDqO5FTJBNOJRAE5YtV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bFK2EbblgRSlVCOt9TEnRnSaG41bUEr1B9oDd2nvu8EgA4i+6uPylz/nlZRS/thKfLLWeo7pPAY1Bx5QSt0HBAFhSqlJWus+hnP9idwQdJlSKh2I11q7woQzp1NKtQGGAy3/boKlJ1NK+WF7k/cubAW+Duiltd5mNJgBynZmMx7I1Fo/ZTqPq7h8Rv6c1rq96Sx/5dXXyMWfjABCgSWXn/g0ynQgZ7r8Ru9jwGJsb+7N8MYSv6w50Be48/JrIfXyGalwUXJGLoQQbk7OyIUQws1JkQshhJuTIhdCCDcnRS6EEG5OilwIIdycFLkQQrg5KXIhhHBz/wdoQmwumilwLQAAAABJRU5ErkJggg==\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": [],
            "needs_background": "light"
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "C-_q5YB4lWfm"
      },
      "source": [
        "# Analytical way :\n",
        "# sinx = x and solve."
      ],
      "execution_count": 133,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "uSOL6iXRlxbb"
      },
      "source": [
        "### Using Newton-Raphson's Method. \n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "lf-uehoHmNiN"
      },
      "source": [
        "Step 1 : $ f(x) = 0 $\n",
        "\n",
        "Step 2 : $ x_{n+1} = x_{n} - \\frac{f(x_n)}{ f'(x_n)} $\n",
        "\n",
        "Repeat Step 2 till Convergence."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vKac8sHBlwcp"
      },
      "source": [
        "import math"
      ],
      "execution_count": 139,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "9M6nwX7nmywQ"
      },
      "source": [
        "# f(x) = 1 + x - sin(x) \n",
        "# f'(x) = 1 - cos(x)\n",
        "\n",
        "f = lambda x_0 : 1 + x_0 - math.sin(x_0)\n",
        "fdash = lambda x_0 : 1 - math.cos(x_0)\n",
        "\n",
        "\n",
        "\n",
        "x0 = 1\n",
        "for i in range(2):\n",
        "  x0 = x0 - f(x0)/fdash(x0)\n",
        "\n",
        "root = x0"
      ],
      "execution_count": 150,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "wXjvAl4wm8z5",
        "outputId": "0e6c1f88-88ff-465f-a2d9-77b0c239bcf4"
      },
      "source": [
        "root"
      ],
      "execution_count": 154,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "-2.0242117630700327"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 154
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "XvvWzeghn0oz",
        "outputId": "103f2f3a-790a-48c6-cb1e-4e7ab8fb77af"
      },
      "source": [
        "math.sin(root)"
      ],
      "execution_count": 157,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "-0.8989562562324447"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 157
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "iVaPdDvvoSJQ",
        "outputId": "fb9897d3-27ed-4198-940e-51f554e35e26"
      },
      "source": [
        "1 + root"
      ],
      "execution_count": 156,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "-1.0242117630700327"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 156
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "X4Cz_ur4olVH"
      },
      "source": [
        "# Homework Project :\n",
        "\n",
        "1. Finding Square Root Using Loops (Newton-Raphson). \n",
        "\n",
        "2. Klinkenberg Effect (Tarek Ahmed) using Newton Raphson.\n",
        "\n",
        "Source to Learn : https://www.youtube.com/watch?v=IHV7NO3akJ0&list=PLLwtZopJNyqZQ2n-UV0chlF3GXRL8f-ox"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "qXSpELTsoVQE"
      },
      "source": [
        ""
      ],
      "execution_count": null,
      "outputs": []
    }
  ]
}